﻿using BCDto.Common.WebsiteConfiguration;
using BCDto.MakeStaticPagingComponent.TemplateTag;
using BCService.Common.WebsiteConfigurationService;
using BCService.MakeStaticPagingComponent.TemplateTagService;
using BCService.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
using System.Text;

namespace BCService.MakeStaticPagingComponent.PageTemplateSerialize.InitialiseSystemDefine
{
    public class InitialiseSystemDefineService: IInitialiseSystemDefineService
    {
        private readonly IWebsiteConfigurationService websiteConfigurationService;
        private readonly ITemplateTagService templateTagService;

        public InitialiseSystemDefineService(IWebsiteConfigurationService websiteConfigurationService, ITemplateTagService templateTagService)
        {
            this.websiteConfigurationService = websiteConfigurationService;
            this.templateTagService = templateTagService;
        }

        public Dictionary<string, object> Init()
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();

            WebsiteConfigurationDto result = websiteConfigurationService.Get();
            
            PropertyInfo[] properties = result.GetType().GetProperties();

            foreach (PropertyInfo property in properties)
            {
                dic.Add("$$" + property.Name,property.GetValue(result,null));
            }

            IEnumerable<TemplateTagDto> templateTagDtos = templateTagService.Get();
            foreach (var item in templateTagDtos)
            {
                dic.Add("!!" + item.TagName, item.TagValue);
            }

            return dic;
        }
    }
}
